	<?php $this->load->view('common/head')?>
	
	<!-- Begin of Sidebar -->
	<?php $this->load->view('common/sidebar')?>

	<?php /****************************/ ?>
	
	<style>
		.highlight { background-color: yellow }
		#side_{
			background: none repeat scroll 0 0 #000000;
			border: 1px solid #3D5565;
			border-radius: 7px 7px 7px 7px;
			color: #FFFFFF;
			opacity: 0.9;
			padding: 5px 10px;
			position: fixed;
			width: 350px;
			z-index: 99;
			overflow:auto;
			height:400px;
			right:0px;
			
		}
		#close{
		clear: both;
		cursor: pointer;
		display: block;
		float: right;
		font-weight: bold;
		text-align: right;
		}
		#hard-bg {
			!important background-color:cyan;
			border-radius: 7px 7px 7px 7px;
			width:80%;
		}
		.dataTables_filter {
float: none;
    margin-bottom: -10px;
    padding-left: 115px;
    padding-top: 10px;
    text-align: left;
}

.dataTables_info {
    border-top: 1px solid #5E6367;
    color: red;
    float: left;
    padding: 5px;
    width: 100%;
}
.hide{display:none}		
.dataTables_empty{color:red}
#table-example_processing{
	background: url("<?php echo $this->config->item('images')?>/loading2.gif") no-repeat scroll left center transparent;
    color: red;
    margin: 5px;
    padding: 5px;
    }
	</style>

    <div class="overlay" style="opacity: 0.8;width: 100%; height: 100%; z-index: 1001; display:none;position: fixed;overflow:hidden;background: none repeat scroll 0 0 #000000;">
		<center><p style='color:#ffffff'>Loading...</p>
		<p class=''>
		<img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." />
		</p>
</center>
</div>

	<?php /****************************/ ?>
	<script defer src="<?php echo $this->config->item('js')?>/jquery.highlight-4.closure.js"></script> <!-- highlight -->
	<div id="side_" style='display:none'><span id="close">(x)</span>

			<p><a href="javascript:;" onclick="step1()" class="button">Done?</a></p>

		<ul></ul>
	</div>
	<!-- Modal Box Content -->
	<div id="dialog2" title="" style="display: none;">
		<p class='mail'>
			<div>
				<label for="template">Select a Template</label>
				<select id="template" name="template" class='required'>
					<option value="">Select a Template</option>
					<?php foreach($mail_templates as $template):?>
						<option value="<?php echo $template->id?>"><?php echo $template->subject?></option>
					<?php endforeach;?>
				</select>
			</div>
			<div>
				<label for="lang">Send As</label>
				<select id="lang" name="lang" class='required'>
					<option value="">Select a Lang</option>
					<option value="ar">Arabic</option>
					<option value="en">English</option>
				</select>
			</div>
		</p>
	</div>
	
	<!-- Modal Box Content -->
	<div id="dialog3" title="" style="display: none;">
		<p class='p3'>	</p>
	</div> 
	<!--! end of #info-dialog -->
	
	<!-- Modal Box Content -->
	<div id="dialog" title="" style="display: none;">
		<p class='p1'>
			<ul>
				<li><b>Export:</b> Export The Current selected data to (PDF, CSV, Excel.. etc)</li>
				<li><b>Print:</b> Open The Current selected data in stand alone table page to print</li>
				<li><b>Mass Mail:</b> Send Mass Mail to all listed Email (Contacts) inside these Companies</li>
				<li><b>Mass SMS:</b> Send Mass SMS to all listed Email (Contacts) inside these Companies</li>
				<li><b>Cancel:</b> Close The current window (Exit)</li>
			</ul>
		</p>
		<p class="p2"></p>
	</div> 
	<!--! end of #info-dialog -->
	
    <!-- Begin of #main -->
    <div id="main" role="main">
    	
    	<!-- Begin of titlebar/breadcrumbs -->
		<div id="title-bar">
			<ul id="breadcrumbs">
				<li><a href="<?php echo site_url()?>" title="Home"><span id="bc-home"></span></a></li>
				<li><a href="search" title="Search">Search</a></li>
				<li class="no-hover">Companies Table</li>
			</ul>
		</div> <!--! end of #title-bar -->
		
		<div class="shadow-bottom shadow-titlebar"></div>
		
		<!-- Begin of #main-content -->
		<div id="main-content">
			<div class="container_12">
			
			<!-- Put your content here! -->
			<div class="grid_12">
				<div class="block-border">
					<div class="block-header"><h1>Search</h1></div>
					<div class="block-content"></div>
				</div>
			</div>
			
			<!--  -->
		<div class="grid_12">
							
				<div class="block-border">
					<div class="block-header">
						<h1 style="cursor:cell;" id="for_title" onClick="">Search - Company Table View</h1><span></span>
					</div>
					<div class="block-content demo">

							
						<div>
							
						<table id="table-example" class="table">
							<thead>
								<tr>
									<th><input type="checkbox" name="" id="check_all" value="" /></th>
									<th>Name</th>
									<th>Flag(s)</th>
									<th>Country/City</th>
									<th>Phone</th>
									<th>Notes</th>
									<th class="hide">hidden</th>
								</tr>
							</thead>
							<tbody>

							</tbody>
						</table>

						<div class="clear"></div>
						</div>
					</div>
					
				</div>
				
			</div>
			
			<div class="clear height-fix"></div>

		</div></div> <!--! end of #main-content -->
  </div> <!--! end of #main -->	

<div class="clear height-fix"></div>

	<script type="text/javascript">
		$().ready(function() {

		/*** dataTable plugin **/
		$('#table-example').dataTable( {
		"bPaginate": false,
		"sScrollY": "300px",
		"bStateSave": true,
		"bProcessing": true,
		"sAjaxSource": "<?php echo site_url('search/company/1')?>",
		"aoColumns": [
						{ "mData": "box" },
						{ "mData": "name" },
						{ "mData": "Flags" },
						{ "mData": "Country" },
						{ "mData": "Phone" },
						{ "mData": "notes" },
						{ "mDataProp": "other", "sClass": "hide" }
					]
		} );
		/****************************/
			
			
			
		/* select all */
		$("#check_all").click(function(){
			var x= $("#check_all").attr('checked');
			$( ".overlay" ).fadeIn()
			
			window.setTimeout(function(){
				if(x){
					$('input:checkbox[name="checkbox[]"]').attr('checked', 'checked').parent().addClass('checked')
				}else{
					$('input:checkbox[name="checkbox[]"]').removeAttr('checked').parent().removeClass('checked')
				}
					
				$('input:checkbox[name="checkbox[]"]').each(function(index) {
					addToList($(this).val())
				});
				
				if(!x) $('#side_').fadeOut();
				
				$( ".overlay" ).fadeOut()
			}, 1500);
			
			
		});
		
		/* add highlight */
		$('.dataTables_filter input').keyup(function() {
			  $('.table td').removeHighlight();
			  $('.table td').highlight($('.dataTables_filter input').val());
		});
		
		$('#close').click(function(){
			$(this).parent().fadeOut()
		});
		
		
	});
	
	function full_d(id)
		{
			var xx = $('#td_'+id).html();
			$('#dialog3 p').html(xx);
			$("#dialog3").dialog({title:$('#td_'+id+' #tdname').text(), autoOpen:true});
		}
		
	function addToList(id)
	{
		$('#side_').fadeIn();
		var xx 		= $('#check_'+id);
		var title 	= xx.attr('title');
		var value 	= xx.val();
		var checked	= xx.attr('checked');

		if(checked){
				$('#side_ ul').append('<li style="display:none" id="side_li_'+value+'">'+title+'</li>');
				$('#side_li_'+value).fadeIn();
				$('#side_li_'+value).append('<input type="hidden" value="'+id+'" name="list[]" />');
				
			}else{
				if(!checked)
					$('#side_li_'+value).fadeOut().remove();
			}
	}
	
	
	function step1()
	{
			$( "#dialog" ).dialog({
				title: "What You Want to Do?",
				resizable: false,
				height:300,
				width:485,
				modal: true,
				buttons: {
					"Export (PDF)?": function() { step2('export')},
					"Mass Mail ?": function() {step2('massmail')},
					"Mass SMS ?": function() {step2('sms')},
					Cancel: function() {$( this ).dialog( "close" )}
				}
			});
	}
	
	function step2(action)
	{
		if(action=='massmail'){
			$( "#dialog2" ).dialog({
				title: "Send Mail Options",
				modal: true,
				buttons: {
					"Send Now": function(){step2('mail')},
					Cancel: function() {$( this ).dialog( "close" )}
				}
			})
			return 0;
		}
			
		var x = $('input[name="list[]"]');
		var msg = '';
		if(action=='mail'){
			
			if($('#template').val()==''){
				msg= msg + 'Select a template';
				$('#template').css('border','1px solid red')
			}
			if($('#lang').val()==''){
				$('#lang').css('border','1px solid red')
				msg= msg + '\nSelect a Lang';
			}

			if(msg!=''){
				
				alert(msg); 
				return false;
			}
			
			$( "#dialog2" ).dialog('close');
			x = $('input[name="list[]"], #template, #lang');
			
		
		}
		
		$('.p2').html('<center><img src="<?php echo $this->config->item('images')?>/loading2.gif" alt="Loading..." title="Loading..." /> Loading... </center>');

		$.post('<?php echo site_url('search/com_list')?>/'+action, x,
		function(data){
			
				
			}, 'json')
		.success(function(data) { if(data.result=='') $('.p2').html('<a target="_blank" href="<?php echo base_url()?>/temp/'+data.file+'">Click Here</a>') })
		.error(function(data) { $('.p2').html('<div class="ui-widget"><div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span><strong>ERROR:</strong> <i></i> Sorry we can not generate the file now, you can try in few min.<br>Thanks..</p></div></div>') })	
		.complete(function(data){
			
			if(action=='mail'){
				$('.p2').html('Result: <hr>');
				var obj = jQuery.parseJSON(data.responseText);
				$.each(obj, function(index,value){
					//$('.p2').append(index+' '+value.name+' <br>');
					
					if(value.result)
						$('.p2').append('<span class="success"><img src="<?php echo $this->config->item('images')?>/icons/packs/fugue/16x16/tick-circle.png" />: ')
					else
						$('.p2').append('<span class="error"><img src="<?php echo $this->config->item('images')?>/icons/packs/fugue/16x16/minus-circle.png" />: ')
					$('.p2').append(' '+value.name+' </span><br>')
				})
			}//end if
			
		})
	}

    </script>



	
	
	
	
	<?php /*********************************/ ?>
	<!-- Begin of footer -->
	<?php $this->load->view('common/footer')?>
